package com.example.mystoryapp2.ui.main

import androidx.fragment.app.Fragment
import com.example.mystoryapp2.R
import com.example.mystoryapp2.contexts.AppContext
import com.example.mystoryapp2.ui.base.BaseViewModel
import com.example.mystoryapp2.ui.main.fragments.AuthorHomeFragment
import com.example.mystoryapp2.ui.main.fragments.ReaderHomeFragment
import com.example.mystoryapp2.ui.main.fragments.SettingFragment

class MainViewModel: BaseViewModel() {
    private var fragmentList = HashMap<Int,Fragment>()

    fun getFragment(id:Int):Fragment?{
        if (!fragmentList.containsKey(id)){
            when(id){
                R.id.setting->{
                    fragmentList[id] = SettingFragment.newInstance()
                }
                R.id.home->{
                    if(!AppContext.isAuthor()){
                        fragmentList[id] = ReaderHomeFragment.newInstance()
                    }else{
                        fragmentList[id] = AuthorHomeFragment.newInstance()
                    }
                }
            }
        }
        return fragmentList[id]
    }
}

